<?php

autoLoader();

$strAction = ( ( true == isset( $_GET['action'] ) && true == valStr( $_GET['action'] ) ) ? $_GET['action'] : NULL );

	$intPatientId 			= '';
	$intCasePaperId			= '';
	$strName 				= '';
	
	$objPatient 	= new Patients();
	$objCasePaper 	= new CasePapers();
	
	if( true == isset( $_GET['patient_id'] ) && true == valStr( $_GET['patient_id'] ) ) {
		$intPatientId 	= ( int ) $_GET['patient_id'];
		$objPatient = $objPatient->fetchPatientsById( $intPatientId );
	}
	
	if( true == isset( $_GET['case_paper_id'] ) && true == valStr( $_GET['case_paper_id'] ) ) {
		$intCasePaperId 	= ( int ) $_GET['case_paper_id'];
		$objCasePaper = $objCasePaper->fetchCasePapersById( $intCasePaperId );
	}
	
	$arrobjPatientNotes = array();
	
	if( true == valObj( $objPatient, 'BasePatients' ) ) {
		$objPatientNote = new PatientNotes();
		
		$strSql = 'SELECT * FROM patient_notes WHERE patient_id = ' . $objPatient->getId() . ';';
		$arrobjPatientNotes = $objPatientNote->fetchSql( $strSql );
	}
	
	$objSonography 			= new Sonography();
	$objUrine 				= new Urines();
	$objWidalReaction 		= new WidalReactions();
	$objXray 				= new Xrays();
	$objBlood 				= new Bloods();
	$objMedicalPerception 	= new MedicalPerceptions();
	
	if( true == valObj( $objPatient, 'BasePatients' ) && true == valObj( $objCasePaper, 'BaseCasePapers' ) ) {
		
		// Sonography Details Loaded.
		$strSql = 'SELECT * FROM sonography WHERE patient_id = ' . ( int ) $objPatient->getId() . ' AND case_paper_id = ' . ( int ) $objCasePaper->getId() . ';';
		$arrobjSonographies = $objSonography->fetchSql( $strSql );
		
		// Urine Details Loaded.
		$strSql = 'SELECT * FROM urines WHERE patient_id = ' . ( int ) $objPatient->getId() . ' AND case_paper_id = ' . ( int ) $objCasePaper->getId() . ';';
		$arrobjUrines = $objUrine->fetchSql( $strSql );
		
		// Widal Reaction Details Loaded.
		$strSql = 'SELECT * FROM widal_reactions WHERE patient_id = ' . ( int ) $objPatient->getId() . ' AND case_paper_id = ' . ( int ) $objCasePaper->getId() . ';';
		$arrobjWidalReactions = $objWidalReaction->fetchSql( $strSql );
		
		// Xray Details Loaded.
		$strSql = 'SELECT * FROM xrays WHERE patient_id = ' . ( int ) $objPatient->getId() . ' AND case_paper_id = ' . ( int ) $objCasePaper->getId() . ';';
		$arrobjXrays = $objXray->fetchSql( $strSql );
		
		// Xray Details Loaded.
		$strSql = 'SELECT * FROM bloods WHERE patient_id = ' . ( int ) $objPatient->getId() . ' AND case_paper_id = ' . ( int ) $objCasePaper->getId() . ';';
		$arrobjBloods = $objBlood->fetchSql( $strSql );
		
		// Medical Perception Details Loaded.
		$strSql = 'SELECT * FROM medical_perceptions WHERE patient_id = ' . ( int ) $objPatient->getId() . ' AND case_paper_id = ' . ( int ) $objCasePaper->getId() . ';';
		$arrobjMedicalPerceptions = $objMedicalPerception->fetchSql( $strSql );		
	}
?>
<link rel="stylesheet" type="text/css" href="css/printing.css" />

<div id="yellow_page_data" style="margin-left: 30px;">
	<div style="margin-top:5px; margin-bottom: 10px; margin-left: 30px;">
		<input type="button" class="btn btn-primary" onclick="window.location.href='modules.php?file=ipd_yellow_page&action=add&patient_id=<?php echo $intPatientId; ?>&mid=<?php echo $mid;?>&smid=<?php echo $smid;?>'" name="add_yellow_pages" value="Add New Note">
		<input type="button" class="btn btn-primary" onclick="window.location.href='modules.php?file=ipd_yellow_page&patient_id=<?php echo $intPatientId; ?>&mid=<? echo $mid;?>&smid=<? echo $smid;?>'" name="add_yellow_pages" value="View Yellow Pages">
	</div>
	
	<div id="parint_working_area" style="border-style: solid; padding-left: 10px;">
		<div class="main_header">
			<div id="main_header" style="text-align: center;">
				<div>SARDAR VALLABHABHAI PATEL CANTONMENT GENETAL HOSPITAL</div>
				<div>Golibar Maidan, Shankar Sheth Road, Pune - 411 001.</div>
				<div><u>MEDICAL CASE SHEET</u></div>
			</div>
			<hr>
			<div id="note">
				Note:- All connected medical documents, viz. clinical chart, Laboratory report, X-ray report, X-ray films and Specialist's report etc. will be securely fastened to this case sheet.
			</div>
		</div>
		
		<div style="height: 10; border-top-style: solid;"></div>
		
		<div id="patient_info">
			<div>
				<div class="patient_info">
					<div style="float: left; width: 50%;">Wrad:- 145</div>
					<div>Religion:- Indian</div>
					<div style="clear: both;"></div>
				</div>
				
				<div class="patient_info">
					<div style="float: left; width: 50%;">A & D Reg No.:- 15215</div>
					<div>Address:- A/T Ranzani POst Bhimanagr</div>
					<div style="clear: both;"></div>
				</div>
				
				<div class="patient_info">
					<div style="float: left; width: 50%;">Name:- <b>Somnath Shinde</b></div>
					<div>House No.:- MHSMR-55</div>
					<div style="clear: both;"></div>
				</div>
				
				<div class="patient_info">
					<div style="float: left; width: 50%;">Age & Sex:- 24 / Male</div>
					<div>Occupation of Patient/ Guardian:- Farmer</div>
					<div style="clear: both;"></div>
				</div>
				
				<div class="patient_info">
					<div style="float: left; width: 50%;">Date and time of Admission:- <?php echo date( 'm/d/Y H:m:s' ); ?></div>
					<div style="margin-top: 5px;">Monthly Income:- 30,465</div>
					<div style="clear: both;"></div>
				</div>
				
				<div class="patient_info">
					<div style="width: 50%;">Date & Time Of Discharge:- <?php echo date( 'm/d/Y H:m:s' ); ?></div>
				</div>
				
				<div class="patient_info">
					<div style="float: left; width: 50%;">Relieved / Expired / AMA :- ------</div>
					<div>Diagnosis:- Fevor</div>
					<div style="clear: both;"></div>
				</div>
			</div>
			
			<hr/>
			
			<div id="patient_relationship_detials">
				<div id="admit_basic_details">
					<div id="brought_details" class="left_side" style="float: left;">
						<div>Date And Time :- <?php date( 'm/d/Y H:m:s' ); ?></div>
						<div>Patient Brought By...</div>
						<div>Name:- Kiran Shinde</div>
						<div>Address:- </div>
					</div>
					
					<div id="admitted" style="margin-left: 10px; float: right; width: 68%;">
						<div>Admitted At :- <?php echo 'Male '; ?> &nbsp; Ward</div>
						<div>M. O. on duty: - TYpe of nurs duty</div>
						<div>Name :- XYZ nam here</div>
					</div>
				</div>
			</div>
			
			<div style="clear: both;"></div>
			<hr>
				
			<div id="note_all_details">
				<div style="float: left;" class="left_side" >
					<div>Investigations advised:-</div>
					<div style="margin-top: 20px;"></div>
					
					<?php
						if( true == valArr( $arrobjSonographies ) ) {
							echo "<div><b>Sonography Reports..</b></div>";
							foreach( $arrobjSonographies as $objSonography ) {
								echo '<div><a id="modules.php?file=fetch_investigation_details&type=fetch&action=sonography&id=' . $objSonography->getId() . '" class="divExpand" title="Click for more details about Sonography report...">(' . $objSonography->getId() . ') ' . $objSonography->getNote() . '</a></div>';
							}
						}

						if( true == valArr( $arrobjUrines ) ) {
							echo "<div><b>Urines Reports..</b></div>";
							foreach( $arrobjUrines as $objUrine ) {
								echo '<div><a id="modules.php?file=fetch_investigation_details&type=fetch&action=urine&id=' . $objUrine->getId() . '" class="divExpand" title="Click for more details about Urine report...">(' . $objUrine->getId() . ') ' . $objUrine->getColor() . '</a></div>';
							}
						}
						
						if( true == valArr( $arrobjXrays ) ) {
							echo "<div><b>XRay Reports..</b></div>";
							foreach( $arrobjXrays as $objXray ) {
								echo '<div><a id="modules.php?file=fetch_investigation_details&type=fetch&action=xray&id=' . $objXray->getId() . '" class="divExpand" title="Click for more details about X-Ray report...">(' . $objXray->getId() . ') ' . $objXray->getDescription() . '</a></div>';
							}
						}
						
						if( true == valArr( $arrobjBloods ) ) {
							echo "<div><b>Bloods Reports..</b></div>";
							foreach( $arrobjBloods as $objBlood ) {
								echo '<div><a id="modules.php?file=fetch_investigation_details&type=fetch&action=blood&id=' . $objBlood->getId() . '" class="divExpand" title="Click for more details about Blood report...">(' . $objBlood->getId() . ') ' . $objBlood->getRemark() . '</a></div>';
							}
						}
						
						if( true == valArr( $arrobjWidalReactions ) ) {
							echo "<div><b>Widal Reactions Reports..</b></div>";
							foreach( $arrobjWidalReactions as $objWidalReaction ) {
								echo '<div><a id="modules.php?file=fetch_investigation_details&type=fetch&action=widal_reaction&id=' . $objWidalReaction->getId() . '" class="divExpand" title="Click for more details about Widal Reaction report...">(' . $objWidalReaction->getId() . ') ' . $objWidalReaction->getDescription() . '</a></div>';
							}
						}
						
						if( true == valArr( $arrobjMedicalPerceptions ) ) {
							echo "<div><b>Medical Perceptions Reports..</b></div>";
							foreach( $arrobjMedicalPerceptions as $objMedicalPerception ) {
								echo '<div><a id="modules.php?file=fetch_investigation_details&type=fetch&action=medical_perception&id=' . $objMedicalPerception->getId() . '" class="divExpand" title="Click for more details about medical perception report...">(' . $objMedicalPerception->getId() . ') ' . $objMedicalPerception->getMedicianName() . '</a></div>';
							}
						}
					?>
				</div>
				<div id="all_notes" style="margin-left: 10px; width: 69%; float: right;">
					<?php
						if( true == valArr( $arrobjPatientNotes ) ) {
							foreach( $arrobjPatientNotes as $objPatientNote ) {
								echo "<div class=single_note>";
								echo "<div style='float: left; width: 30%;'>" . $objPatientNote->getDescription() . "</div>";
								echo "<div style='text-align: center;'>" . $objPatientNote->getMedicalDetails() . "</div><div style='clear: both;'></div>";
								echo "<hr/></div>";
							}
						}
					?>
				</div>
			</div>
				<div style="clear: both;"></div>
		</div>
	</div>
	
	<div style="text-align: center; padding-top: 15px;" id="buttons">
		<input type="button" class="btn btn-primary" value="Print" name="print_doc" onclick="PrintDoc();" />
		<input type="button" class="btn btn-primary" name="print_preview" value="Print Preview" onclick="PrintPreview();" />
	</div>
	<div style="text-align: center; padding-top: 15px;" id="operation_buttons">
		<input type="button" class="btn btn-primary" onclick="window.location.href='modules.php?file=ipd_yellow_page&action=add&patient_id=<?php echo $intPatientId; ?>&mid=<?php echo $mid;?>&smid=<?php echo $smid;?>'" name="add_yellow_pages" value="Add New Note">
		<input type="button" class="btn btn-primary" onclick="window.location.href='modules.php?file=ipd_yellow_page&patient_id=<?php echo $intPatientId; ?>&mid=<? echo $mid;?>&smid=<? echo $smid;?>'" name="add_yellow_pages" value="View Yellow Pages">
	</div>
</div>

<script type="text/javascript">

/*--This JavaScript method for Print command--*/

function PrintDoc() {
	var toPrint = document.getElementById('parint_working_area');
	var popupWin = window.open('', '_blank', 'width=900,height=700,location=no,left=100px');

	popupWin.document.open();
	popupWin.document.write('<html><title>::Preview::</title><link rel="stylesheet" type="text/css" href="css/printing.css" /></head><body onload="window.print()">')
	popupWin.document.write( toPrint.innerHTML );
	popupWin.document.write('</html>');
	popupWin.document.close();
}

/*--This JavaScript method for Print Preview command--*/
function PrintPreview() {
	var toPrint = document.getElementById('parint_working_area');
	var popupWin = window.open('', '_blank', 'width=900,height=700,location=no,left=100px');

	popupWin.document.open();
	popupWin.document.write('<html><title>::Print Preview::</title><link rel="stylesheet" type="text/css" href="css/printing.css" media="screen"/></head><body">')
	popupWin.document.write( toPrint.innerHTML );
	popupWin.document.write('</html>');
	popupWin.document.close();
}
</script>